﻿@{
    Layout = null;
}

<!DOCTYPE html>

<html>
<head>
    <title>Index</title>
    <script src="~/lib/jquery/1.12.4/jquery.min.js"></script>
    <script src="~/lib/bootstrap/3.3.4/js/bootstrap.min.js"></script>
    <link href="~/lib/bootstrap/3.3.4/css/bootstrap.min.css" rel="stylesheet" />
    <link href="~/css/framework-font.css" rel="stylesheet" />
    <link href="~/css/framework-theme.css" rel="stylesheet" />
    <link href="~/lib/select2/select2.min.css" rel="stylesheet" />
    <script src="~/lib/select2/select2.min.js"></script>
    <link href="~/lib/jqgrid/5.3.0/css/ui.jqgrid-bootstrap.css" rel="stylesheet" />
    <script src="~/lib/jqgrid/5.3.0/js/jquery.jqGrid.js"></script>
    <script src="~/lib/jqgrid/5.3.0/i18n/grid.locale-cn.js"></script>
    <link href="~/css/framework-ui.css" rel="stylesheet" />
    <script src="~/js/framework-ui.js"></script>
    <style>
        .ui-jqgrid tr.jqgrow td {
            vertical-align :middle;
            padding: 2px;
        }
    </style>
</head>
<body>
    <div class="topPanel">
        <div class="toolbar">
            <div class="btn-group">
                <a class="btn btn-primary" onclick="$.reload()"><span class="glyphicon glyphicon-refresh"></span></a>
            </div>
            <div class="btn-group">
                <a class="btn btn-primary" onclick="batchGetUserInfo()"><span class="glyphicon glyphicon-cloud-download"></span> 同步微信用户信息</a>
            </div>
            <div class="operate">
                <ul class="nav nav-pills">
                    <li class="first">已选中<span>1</span>项</li>
                    <li><a id="NF-Sync" authorize="no" onclick="getUserInfo()"><i class="fa fa-cloud-download"></i>同步用户信息</a></li>
                    <li><a id="NF-Edit" authorize="no" onclick="btn_edit()"><i class="fa fa-pencil-square-o"></i>编辑公众号</a></li>
                    <li><a id="NF-Delete" authorize="no" onclick="btn_delete()"><i class="fa fa-trash-o"></i>删除公众号</a></li>
                    <li><a id="NF-Details" authorize="no" onclick="btn_details()"><i class="fa fa-search-plus"></i>查看公众号</a></li>
                    <li class="split"></li>
                    <li><a id="NF-Enter" authorize="no" onclick="btn_enter()"><i class="fa fa-search-plus"></i>进入公众号</a></li>
                </ul>
                <a href="javascript:;" class="close"></a>
            </div>
            <script>$('.toolbar').authorizeButton()</script>
        </div>
        <div class="search">
            <table>
                <tr>
                    <td>
                        <div class="input-group">
                            <input id="txt_keyword" type="text" class="form-control" placeholder="昵称/手机" style="width: 200px;">
                            <span class="input-group-btn">
                                <button id="btn_search" type="button" class="btn  btn-primary"><i class="fa fa-search"></i></button>
                            </span>
                        </div>
                    </td>
                </tr>
            </table>
        </div>
    </div>
    <div class="gridPanel">
        <table id="gridList"></table>
        <div id="gridPager"></div>
    </div>
    <script>
        $(function () {
            gridList();
        })
        function gridList() {
            var $gridList = $("#gridList");
            $gridList.dataGrid({
                url: "/WeixinManage/WxUser/GetGridJson",
                height: $(window).height() - 103,
                colModel: [
                    { label: 'Id', name: 'Id', hidden: true, key: true },
                    { label: 'AppId', name: 'AppId', hidden: true },
                    { label: 'OpenId', name: 'OpenId', hidden: true },
                    {
                        label: '头像', name: 'HeadImgUrl', width: 30, align: 'center', sortable: false,
                        formatter: function (cellvalue) {
                            console.log(cellvalue);
                            return '<img alt="image"  height="28" width="28" src="' + cellvalue + '" onerror="this.src=\'/img/image_picture_48px.png\'">';
                        }
                    },
                    { label: '昵称', name: 'Nickname', width: 100, align: 'center', sortable: false },
                    { label: '手机', name: '', width: 100, align: 'center', sortable: false },
                    {
                        label: '性别', name: 'Sex', width: 30, align: 'center', sortable: false,
                        formatter: function (cellvalue) {
                            if (cellvalue == 1) return "男";
                            else if (cellvalue == 0) return "女";
                            else return "";
                        }
                    },
                    { label: '国家', name: 'Country', width: 50, align: 'center', sortable: false },
                    { label: '省份', name: 'Province', width: 50, align: 'center', sortable: false },
                    { label: '城市', name: 'City', width: 50, align: 'center', sortable: false },
                    { label: '语言', name: 'Language', width: 50, align: 'center', sortable: false }, 
                    { label: '关注时间', name: 'SubscribeTime', width: 100, align: 'center', sortable: false },
                ],
                pager: "#gridPager",
                sortname: 'Id asc',
                viewrecords: true,
            });
            $("#btn_search").click(function () {
                $gridList.jqGrid('setGridParam', {
                    postData: { keyword: $("#txt_keyword").val() },
                }).trigger('reloadGrid');
            });
        }

        function batchGetUserInfo() {
            $.modalConfirm("注：只能同步已关注该公众号的用户信息，并且之前没有同步过用户信息，已取消关注的用户无法同步，您确定要同步微信用户信息吗？", function (r) {
                if (r) {
                    $.submitForm({
                        url: "/WeixinManage/WxUser/BatchGetUserInfo",
                        param: {},
                        success: function () {
                            $.currentWindow().$("#gridList").trigger("reloadGrid");
                        }
                    })
                }
            });
        }
    </script>
</body>
</html>
